package com.computergames.server.service.GameStrategy;

import com.computergames.server.message.Message;
import com.computergames.server.message.MoveRequestMessage;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class StrategySelector {
    private final Map<Integer, MessageHandlingStrategy> strategyMap = new ConcurrentHashMap<>();

    public StrategySelector() {
        strategyMap.put(Message.GobangMessage, new GobangMessageHandler());
        strategyMap.put(Message.LandlordMessage, new LandlordMessageHandler());
    }

    public int select(int messageType, MoveRequestMessage msg, String roomName, ChannelHandlerContext  ctx) {
        MessageHandlingStrategy strategy = strategyMap.get(messageType);
        if (strategy == null) {
            throw new IllegalArgumentException("No strategy found for message type: " + messageType);
        }
        return strategy.handle(msg, roomName, ctx);
    }
}
